home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0156_Re: TEdit and numbers.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  692 b   |  27 lines

  1. {
  2. >I want the user to enter numbers and sometime I want to view numbers on
  3. >screen.
  4. >I use TEdit and must convert the data everytime.
  5. >Is there any other component to use, so I can have the data directly
  6. >to integers and real?
  7. Just create a custom component that adds a property to do the
  8. conversion for you, e.g.,
  9. }
  10. type
  11.   TIntegerEdit = class(TEdit)
  12.   private
  13.     function GetInt: LongInt;
  14.     procedure SetInt(Value: LongInt);
  15.   public
  16.     property IntValue: LongInt read GetInt write SetInt;
  17.   end;
  18. function TIntegerEdit.GetInt: LongInt;
  19. begin
  20.   Result := StrToInt(Text)
  21. end;
  22. procedure TIntegerEdit.SetInt(Value: LongInt);
  23. begin
  24.   Text := IntToStr(Value)
  25. end;
  26.  
  27.